<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改企业信息')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-tenant-edit" th:object="${tenant}">
            <input name="parentCode" th:field="*{parentCode}" type="hidden">
            <input name="tenantCode" th:field="*{tenantCode}" type="hidden">
            <input name="tenantTerm" th:field="*{tenantTerm}" type="hidden">
            <!--<div class="form-group">-->
                <!--<label class="col-sm-3 control-label is-required">租户标识：</label>-->
                <!--<div class="col-sm-8">-->
                    <!--<input name="newTenantCode" th:value="*{tenantCode}" class="form-control" type="text" required>-->
                <!--</div>-->
            <!--</div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">企业名称：</label>
                <div class="col-sm-8">
                    <input name="tenantName" th:field="*{tenantName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">系统昵称：</label>
                <div class="col-sm-8">
                    <input name="tenantNickname" th:field="*{tenantNickname}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">租户邮箱：</label>
                <div class="col-sm-8">
                    <input name="email" th:field="*{email}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">手机号码：</label>
                <div class="col-sm-8">
                    <input name="phonenumber" th:field="*{phonenumber}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">联系地址：</label>
                <div class="col-sm-8">
                    <input name="address" th:field="*{address}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">有效期限：</label>
                <div class="col-sm-8">
                    <input name="params[tenantTerm]" th:value="*{tenantTerm}" class="form-control" type="number" th:min="0">
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 单位为天 0为永久 </span>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">企业状态：</label>
                <div class="col-sm-8">
                    <label class="toggle-switch switch-solid">
                        <input type="checkbox" id="status" th:checked="${tenant.status == '0' ? true : false}">
                        <span></span>
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-3 control-label">角色：</label>
                <div class="col-xs-8">
                    <label th:each="role:${roles}" class="check-box">
                        <input name="role" type="checkbox" th:value="${role.roleId}" th:text="${role.roleName}" th:checked="${role.flag}" th:disabled="${role.status == '1'}">
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-3 control-label">备注：</label>
                <div class="col-xs-8">
                    <textarea name="remark" th:field="*{remark}" maxlength="500" class="form-control" rows="3"></textarea>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">首页地址：</label>
                <div class="col-sm-8">
                    <input name="homepath" th:field="*{homepath}" class="form-control" type="text">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">头logo：</label>
                <div class="col-sm-8">
                    <a class="form-control" id = "titlepathA" name="titlepathA" th:href="@{/}+*{titlepath}">[[*{titlename}]] </a>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">重新上传：</label>
                <div class="col-sm-8">
                    <input name="title" class="form-control" type="file"  onchange="uploadFile('title')">
                    <input id="titlename" name="titlename" th:field="*{titlename}" class="form-control" type="hidden">
                    <input id="titlepath" name="titlepath" th:field="*{titlepath}" class="form-control" type="hidden">
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 只支持格式为*.ico图片,文件名称不能包含中文,大小不能超过3M </span>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">背景：</label>
                <div class="col-sm-8">
                    <a class="form-control" id = "bgpathA" name="bgpathA" th:href="@{/}+*{bgpath}">[[*{bgname}]] </a>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">重新上传：</label>
                <div class="col-sm-8">
                    <input name="bg" class="form-control" type="file"  onchange="uploadFile('bg')">
                    <input id="bgname" name="bgname" th:field="*{bgname}" class="form-control" type="hidden">
                    <input id="bgpath" name="bgpath" th:field="*{bgpath}" class="form-control" type="hidden">
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 只支持格式为*.png、*.jpg图片,文件名称不能包含中文,大小不能超过3M </span>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "system/tenant";
        $("#form-tenant-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var data = $("#form-tenant-edit").serializeArray();
                var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
                var roleIds = $.form.selectCheckeds("role");
                data.push({"name": "status", "value": status});
                data.push({"name": "roleIds", "value": roleIds});
                $.operate.save(prefix + "/edit", data);
            }
        }

        function uploadFile(filePath) {
            $.modal.loading("文件上传中，请勿做其他操作，耐心等待");
            var formData = new FormData();
            if ($("input[name='" + filePath + "']")[0].files[0] == null) {
                $.modal.alertWarning("请先选择文件路径");
                return false;
            }
            formData.append('file', $("input[name='" + filePath + "']")[0].files[0]);
            $.ajax({
                url: ctx + "common/upload",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function (result) {
                    $.modal.closeLoading();
                    if (result.code == '0') {
                        $("#"+filePath+"path").val(result.filePath);
                        $("#"+filePath+"name").val(result.fileName);

                        $("#"+filePath+"pathA").empty();
                        $("#"+filePath+"pathA").append(result.fileName);
                        $("#"+filePath+"pathA").attr("href",ctx+result.filePath);
                    }
                    $.modal.msgSuccess(result.msg);
                }
            });
        }

    </script>
</body>
</html>